package stack.era.presentation.world;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import stack.era.domain.DomainHome;

public class WorldTravelTab extends JPanel {

	private static final long serialVersionUID = 4351646481447406090L;

	private JList townList, resourceLocationList, hiddenLocationList;
	private JButton townTravelButton, resourceLocationTravelButton,
			hiddenLocationTravelButton;

	public WorldTravelTab() {
		super();

		townList = new JList();
		townList.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
		hiddenLocationList = new JList();
		hiddenLocationList.setBorder(BorderFactory.createLineBorder(
				Color.BLACK, 2));
		resourceLocationList = new JList();
		resourceLocationList.setBorder(BorderFactory.createLineBorder(
				Color.BLACK, 2));
		townTravelButton = new JButton("> Travel To Town");
		townTravelButton.setBorder(BorderFactory.createLineBorder(Color.BLACK,
				2));
		resourceLocationTravelButton = new JButton("> Travel To Resource");
		resourceLocationTravelButton.setBorder(BorderFactory.createLineBorder(
				Color.BLACK, 2));
		hiddenLocationTravelButton = new JButton("> Travel To Hidden Location");
		hiddenLocationTravelButton.setBorder(BorderFactory.createLineBorder(
				Color.BLACK, 2));

		JPanel listPanel = new JPanel();
		listPanel.setLayout(new GridLayout(1, 3));
		listPanel.add(new JScrollPane(townList));
		listPanel.add(new JScrollPane(resourceLocationList));
		listPanel.add(new JScrollPane(hiddenLocationList));

		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout(new GridLayout(1, 3));
		buttonPanel.add(townTravelButton);
		buttonPanel.add(resourceLocationTravelButton);
		buttonPanel.add(hiddenLocationTravelButton);

		this.setLayout(new BorderLayout());
		this.add(listPanel, BorderLayout.CENTER);
		this.add(buttonPanel, BorderLayout.SOUTH);

		this.setBorder(BorderFactory.createLineBorder(Color.GRAY, 100));
	}

	public void populate() {
		DomainHome domain = DomainHome.getInstance();
		if (domain.getPlayerCharacter() != null) {
			ArrayList<String> knownTowns = domain.getPlayerCharacter()
					.getAllKnownTowns();
			townList.setListData(knownTowns.toArray());
			ArrayList<String> knownResourceLocations = domain
					.getPlayerCharacter().getAllKnownResourceLocations();
			resourceLocationList.setListData(knownResourceLocations.toArray());
			ArrayList<String> knownHiddenLocations = domain
					.getPlayerCharacter().getAllKnownHiddenLocations();
			hiddenLocationList.setListData(knownHiddenLocations.toArray());
		}
	}
}
